package com.hr.system.controller;

import java.util.List;

import com.hr.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hr.common.annotation.Log;
import com.hr.common.enums.BusinessType;
import com.hr.system.domain.SysAllowance;
import com.hr.system.service.ISysAllowanceService;
import com.hr.common.core.controller.BaseController;
import com.hr.common.core.domain.AjaxResult;
import com.hr.common.utils.poi.ExcelUtil;
import com.hr.common.core.page.TableDataInfo;

/**
 * 员工薪资应发项目Controller
 * 
 * @author ruoyi
 * @date 2021-04-29
 */
@Controller
@RequestMapping("/system/allowance")
public class SysAllowanceController extends BaseController
{
    private String prefix = "system/allowance";

    @Autowired
    private ISysAllowanceService sysAllowanceService;

    @RequiresPermissions("system:allowance:view")
    @GetMapping()
    public String allowance()
    {
        return prefix + "/allowance";
    }

    /**
     * 查询员工薪资应发项目列表
     */
    @RequiresPermissions("system:allowance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysAllowance sysAllowance)
    {
        startPage();
        sysAllowance.setTenantId(ShiroUtils.getTenantId());
        List<SysAllowance> list = sysAllowanceService.selectSysAllowanceList(sysAllowance);
        return getDataTable(list);
    }

    /**
     * 导出员工薪资应发项目列表
     */
    @RequiresPermissions("system:allowance:export")
    @Log(title = "员工薪资应发项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysAllowance sysAllowance)
    {
        sysAllowance.setTenantId(ShiroUtils.getTenantId());
        List<SysAllowance> list = sysAllowanceService.selectSysAllowanceList(sysAllowance);
        ExcelUtil<SysAllowance> util = new ExcelUtil<SysAllowance>(SysAllowance.class);
        return util.exportExcel(list, "allowance");
    }

    /**
     * 新增员工薪资应发项目
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工薪资应发项目
     */
    @RequiresPermissions("system:allowance:add")
    @Log(title = "员工薪资应发项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysAllowance sysAllowance)
    {
        sysAllowance.setTenantId(ShiroUtils.getTenantId());
        return toAjax(sysAllowanceService.insertSysAllowance(sysAllowance));
    }

    /**
     * 修改员工薪资应发项目
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysAllowance sysAllowance = sysAllowanceService.selectSysAllowanceById(id);
        mmap.put("sysAllowance", sysAllowance);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工薪资应发项目
     */
    @RequiresPermissions("system:allowance:edit")
    @Log(title = "员工薪资应发项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysAllowance sysAllowance)
    {
        return toAjax(sysAllowanceService.updateSysAllowance(sysAllowance));
    }

    /**
     * 删除员工薪资应发项目
     */
    @RequiresPermissions("system:allowance:remove")
    @Log(title = "员工薪资应发项目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysAllowanceService.deleteSysAllowanceByIds(ids));
    }
}
